<template>
    <div class="demo-container">
      <!-- 自定义组件引用 -->
      <h3>ExcelJS表格</h3>
      <div @click="generateExcel">生成表格</div>
    </div>
</template>

<script>
import ExcelJS from 'exceljs'
import { GetFileStyle } from './utils'
import jsonData from './mock'

const COLOR = {
	BLUE: "9BC2E6",
	GREEN: "A9D08E",
	REPORT: "9BC2E6"
}

export default {
  name: "ExcelJS",
  data() {
    return {
    }
  },
  created() {
  },
  methods: {
    generateExcel() {
      let {
        filename,
        sheetName,
        sheetDescript,
        header,
        contentLists
      } = jsonData;

      let length = header.length || 4
      let workbook = new ExcelJS.Workbook();
      let sheet = workbook.addWorksheet(sheetName);

      let getFileObj = new GetFileStyle(sheet)
      getFileObj
        .setGeneralValue(1, null, sheetDescript)
        .setGeneralValue(2, 6, header)
        .setGeneralValue(3, null, contentLists)
        .setFontSize("A1")
        .setBorderStyle("thin", "thin", "thin", "thin", "000000", length,6)
        .setBorderRightStyle()
        .setMerge(5, length)
        .setBackgroundColor("A1", COLOR.GREEN)
        .setAlignment("A1", "middle", "center");

      console.log(workbook.xlsx)
      // workbook.xlsx.writeFile(`${filename}.xls`);
      return filename;
    }
  }
};
</script>
